#
# "@(#) $Id: StatusBurnerProgressView.py,v 1.1.1.1 2006-07-27 03:16:08 gioshe Exp $"
#
# This work is released under the GNU GPL, version 2 or later.
#
from Utils.kdeemul import *
from Utils.human import *
from StatusProgressBar import *
from CD.Burner import *
from PixmapPushButton import *
from Utils.Paths import *
from Utils.utils import *

class StatusBurnerProgressView(QWidget):
	def __init__(self,container,statusView):
		global _backColor
		QWidget.__init__(self,container)
		self.statusView = statusView
		backColor=QColor(Settings.settings().get('ColorR'),Settings.settings().get('ColorG'),Settings.settings().get('ColorB'))
		self.setPaletteBackgroundColor(backColor)
		self.buildViews()
		QObject.connect(Burner.singleton(),PYSIGNAL("status"),self.progress)
	
	def buildViews(self):
		#f = QFont("fixed",6)
		hlayout = QHBoxLayout(self)
		hlayout.addItem(QSpacerItem(1,1,QSizePolicy.Expanding,QSizePolicy.Fixed))
		vlayout = QVBoxLayout()
		vlayout.setSpacing(-5)
		hlayout.addLayout(vlayout,100)
		#vlayout.addItem(QSpacerItem(1,1,QSizePolicy.Fixed,QSizePolicy.Expanding))
		#self.title = QLabel(i18n("Song Name"),self)
		self.title = KSqueezedTextLabel(self)
		self.title.setText("Song Name")
		#self.title.setFont(f)
		self.title.setAlignment(Qt.AlignCenter)
		vlayout.addWidget(self.title)
		self.elapsed = QLabel(i18n("Completion"),self)
		#self.elapsed.setFont(f)
		self.elapsed.setAlignment(Qt.AlignCenter)
		vlayout.addWidget(self.elapsed)
		playout = QHBoxLayout()
		vlayout.addLayout(playout)
		playout.addItem(QSpacerItem(1,1,QSizePolicy.Expanding,QSizePolicy.Fixed))
		self.progressView = StatusProgressBar(self)
		playout.addWidget(self.progressView)
		playout.addItem(QSpacerItem(1,1,QSizePolicy.Expanding,QSizePolicy.Fixed))
		#vlayout.addItem(QSpacerItem(1,1,QSizePolicy.Fixed,QSizePolicy.Expanding))
		hlayout.addItem(QSpacerItem(1,1,QSizePolicy.Expanding,QSizePolicy.Fixed))
		cancelIcon = QIconSet(QPixmap(art("buttonstatuscancel.png")))
		self.cancelButton = SmallPixmapPushButton(cancelIcon,"",self)
		QToolTip.add(self.cancelButton,i18n("Cancel the burn"))
		QObject.connect(self.cancelButton,SIGNAL("clicked()"),self.cancelBurn)
		hlayout.addWidget(self.cancelButton)
		
	def progress(self,status):
		self.progressView.progress(status)
		state = status['Status']
		if state=='Begin':
			self.title.setText('Preparing Tracks')
			self.elapsed.setText('')
			self.statusView.showStatus(self)
		elif state=='Preparing':
			self.title.setText('Preparing CD')
		elif state=='Converting' or state=='Burning':
			self.title.setText("%s: %s" % (state,status['Track'].title))
			percentage = long(100*status['currentTime']/status['totalTime'])
			self.elapsed.setText(unikode(i18n('Completion: %d%%')) % percentage)
		elif state=='Building Image' or state=='Burning Image':
			self.title.setText("%s" % state)
			percentage = long(100*status['currentTime']/status['totalTime'])
			self.elapsed.setText(unikode(i18n('Completion: %d%%')) % percentage)
		elif state=='End':
			self.statusView.hideStatus(self)

	def cancelBurn(self):
		CD.Burner.killCurrentBurner()
